package com.ruoyi.auth.MyThread;

import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.stereotype.Component;

import java.util.Collection;
@Component
public class Mythread extends Thread{
    public String userName;

    public RedisService redisService;

    public Collection<String> keys;


    public Collection<String> getKeys() {
        return keys;
    }

    public void setKeys(Collection<String> keys) {
        this.keys = keys;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public RedisService getRedisService() {
        return redisService;
    }

    public void setRedisService(RedisService redisService) {
        this.redisService = redisService;
    }

    @Override
    public void run(){
        /*单点登录*/
//        Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
        for (String key : keys)
        {
            LoginUser y = redisService.getCacheObject(key);
            if (y.getUsername().equals(userName)){
                redisService.deleteObject(key);
            }
        }
    }

}
